package com.jctrip.hotel.source.xxl.cnbe.thread;

import com.jctrip.hotel.common.constant.RedisKeyConstant;
import com.jctrip.hotel.common.context.BeanContext;
import com.jctrip.hotel.common.util.RedisUtil;
import com.jctrip.hotel.source.model.CnBooking.CityDataDTO;
import com.jctrip.hotel.source.model.CnBooking.IdentityInfoDTO;
import com.jctrip.hotel.source.service.CNBooking.CNBookingTaskService;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author henry
 * @Date 2023/7/3 22:29
 * @Description
 */
@Slf4j
public class SyncCNBEHotelInfoListTaskThread implements Runnable {
    private final IdentityInfoDTO infoDTO;

    public SyncCNBEHotelInfoListTaskThread(IdentityInfoDTO infoDTO) {
        this.infoDTO = infoDTO;
    }

    @Override
    public void run() {
        RedisUtil redisUtil = BeanContext.getApplicationContext().getBean(RedisUtil.class);

        CNBookingTaskService cnBookingTaskService =
                BeanContext.getApplicationContext().getBean(CNBookingTaskService.class);
        while (redisUtil.lGetListSize(RedisKeyConstant.HOTEL_MAIN_CNBE_CITYID_LIST) > 0) {
            try {
                CityDataDTO cityDataDTO =
                        (CityDataDTO) redisUtil.rightPop(RedisKeyConstant.HOTEL_MAIN_CNBE_CITYID_LIST);
                if (cityDataDTO == null) {
                    continue;
                }
                String lang = "0001".equals(cityDataDTO.getCountryId()) ? "GB" : "EN";
                infoDTO.setLang(lang);
                cnBookingTaskService.syncCNBEHotelInfoListTaskPop(cityDataDTO.getCountryId(),
                        cityDataDTO.getProvinceId(), cityDataDTO.getCityId(), infoDTO);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }
    }
}
